package com.mingtu.dzpatrol.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mingtu.dzpatrol.R;

/**
 * 描述：
 * 修改人：
 * 修改时间：
 * 修改备注：
 *
 * @author wkk
 */

public class EmptyDataLayout extends RelativeLayout implements View.OnClickListener {


    private TextView tvText;
    private PlaceImgOnClickListener placeImgOnClickListener;
    private ImageView iv;
    private RelativeLayout rlLayout;
    private String placeText;

    public EmptyDataLayout(Context context) {
        this(context, null);
    }
    public EmptyDataLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }
    public EmptyDataLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs,defStyleAttr);
        /**加载布局文件*/
        LayoutInflater.from(context).inflate(R.layout.layout_no_data, this, true);
        rlLayout = (RelativeLayout) findViewById(R.id.rl_layout);
        tvText = (TextView) findViewById(R.id.tv_text);
        iv = (ImageView) (ImageView) findViewById(R.id.iv);

        /**获取属性值*/
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.EmptyDataLayout);

        placeText = typedArray.getString(R.styleable.EmptyDataLayout_placeText);
        Boolean isShow = typedArray.getBoolean(R.styleable.EmptyDataLayout_isShowView, false);
        /**
         * 设置值
         */
        if (TextUtils.isEmpty(placeText)) {
            tvText.setText("暂无数据哦~");
        } else {
            tvText.setText(placeText);
        }

        if (isShow) {
            rlLayout.setVisibility(View.VISIBLE);
        } else {
            rlLayout.setVisibility(View.GONE);
        }

        iv.setOnClickListener(this);

        typedArray.recycle();
    }

    //动态设置文字
    public void setPlaceText(String title) {
        tvText.setText(title);
    }

    //动态设置是否显示

    public void setIsShowView(Boolean b) {
        if (b) {
            rlLayout.setVisibility(View.VISIBLE);
        } else {
            rlLayout.setVisibility(View.GONE);
        }
    }

    /**
     * 设置图片点击监听
     *
     * @param placeImgOnClickListener
     */
    public void setPlaceImgOnClickListener(PlaceImgOnClickListener placeImgOnClickListener) {
        this.placeImgOnClickListener = placeImgOnClickListener;
    }

    @Override
    public void onClick(View v) {
        if (placeImgOnClickListener != null) {
            placeImgOnClickListener.OnClick();
        }
    }

    /**
     * 图片点击事件回调接口
     */
    public interface PlaceImgOnClickListener {
        void OnClick();
    }
}
